﻿Imports System.IO

Public Class Frm_Rech_Avoc_Clients
    Private Sub Frm_Rech_Avoc_Clients_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Frm_Avoc_Bure.Enabled = True
        Frm_Av_Enemi.Enabled = True
        Frm_a7kame.Enabled = True
    End Sub

    Private Sub Frm_Rech_Avoc_Clients_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        comb_matorido_elbaht.SelectedIndex = 0

    End Sub

    Private Sub txt_rech_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_rech.TextChanged
        Try
            List_tous.Items.Clear()
            Partager.list_recherch.Clear()
            If comb_matorido_elbaht.SelectedItem = "رقم البطاقة الوطنية" Then
                For Each av As Avocat_bureau In Partager.moi.List_avocat_bureau
                    If av.type <> "صاحب المكتب" Then
                        If av.Cin.Contains(txt_rech.Text) Then
                            Partager.list_recherch.Add(av)
                            List_tous.Items.Add(New ListViewItem(New String() {av.Cin, av.Nom_a, av.Prenom_a}))

                        End If
                    End If
                Next


            ElseIf comb_matorido_elbaht.SelectedItem = "الاسم العائلي" Then

                For Each av As Avocat_bureau In Partager.moi.List_avocat_bureau
                    If av.type <> "صاحب المكتب" Or Partager.rech Then
                        If av.Nom_a.Contains(txt_rech.Text) Then
                            Partager.list_recherch.Add(av)
                            List_tous.Items.Add(New ListViewItem(New String() {av.Cin, av.Nom_a, av.Prenom_a}))
                        End If
                    End If
                Next

            ElseIf comb_matorido_elbaht.SelectedItem = "الاسم الشخصي" Then

                For Each av As Avocat_bureau In Partager.moi.List_avocat_bureau
                    If av.type <> "صاحب المكتب" Or Partager.rech Then
                        If av.Prenom_a.Contains(txt_rech.Text) Then
                            Partager.list_recherch.Add(av)
                            List_tous.Items.Add(New ListViewItem(New String() {av.Cin, av.Nom_a, av.Prenom_a}))
                        End If
                    End If
                Next

            ElseIf comb_matorido_elbaht.SelectedItem = "الرقم المهني" Then

                For Each av As Avocat_bureau In Partager.moi.List_avocat_bureau
                    If av.type <> "صاحب المكتب" Then
                        If av.Num_prof.ToString.Contains(txt_rech.Text) Then
                            Partager.list_recherch.Add(av)
                            List_tous.Items.Add(New ListViewItem(New String() {av.Cin, av.Nom_a, av.Prenom_a}))
                        End If
                    End If
                Next

            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        If txt_rech.Text = "" Then
            List_tous.Items.Clear()
        End If
    End Sub
    Public Sub choisir()
        If List_tous.SelectedIndices.Count > 0 Then
            Dim avo As Avocat_bureau
            Dim j As Integer = 0
            Try
                For Each i As Integer In List_tous.SelectedIndices
                    avo = Partager.list_recherch(i)
                    For Each khib As Avocat_bureau In Partager.moi.List_avocat_bureau

                        If avo.Id = khib.Id Then
                            If Partager.type = "Frm_Av_Mowakil" Then
                                Frm_Av_Enemi.CombNomAv.Text = khib.Nom_a & "  " & khib.Prenom_a
                            ElseIf Partager.type = "Frm_a7kame" Then
                                Frm_a7kame.Comb_nom.Text = khib.Nom_a & "  " & khib.Prenom_a
                            Else
                                If khib.type <> "صاحب المكتب" Then
                                    Frm_Avoc_Bure.List_tous.Items(j).Focused = True
                                    Frm_Avoc_Bure.List_tous.Items(j).Selected = True
                                End If
                            End If
                        End If
                        j += 1
                    Next
                Next
                Me.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        Else
            MsgBox("اختر محامي من القائمة", MsgBoxStyle.Information, "خطأ في البحث")
        End If
    End Sub

    Private Sub Btn_choisi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_choisi.Click
        choisir()
    End Sub

    Private Sub comb_matorido_elbaht_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles comb_matorido_elbaht.SelectedIndexChanged
        txt_rech.Clear()
    End Sub
End Class